package com.kzd.sdk.utils;

import com.google.gson.JsonSyntaxException;
import com.kzd.sdk.error.KZD_CustomException;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

public class ExceptionUtils {

    public static String getMessage(Throwable throwable) {
        if (throwable instanceof UnknownHostException) { //网络异常
            return "当前无网络，请检查你的网络设置";
        } else if (throwable instanceof SocketTimeoutException) {  //okhttp全局设置超时
            return "连接超时,请稍后再试";
        } else if (throwable instanceof ConnectException) {
            return "网络不给力，请稍候重试！";
        } else if (throwable instanceof JsonSyntaxException) {  //请求成功，但Json语法异常,导致解析失败
            return "数据解析失败,请检查数据是否正确";
        } else if (throwable instanceof KZD_CustomException) {
            return throwable.getMessage();
        } else {
            return "请求失败，请稍后再试！" + throwable.getMessage();
        }
    }
}
